
var fs = require( 'fs' ), stat = fs.stat;
var os = require( 'os' )
var process = require('child_process');


let win = false

//-- clean
console.log("Clean...")

if (!win) {
    process.execSync("rm -rf dist")
    
    console.log("Build js...")
    process.execSync("npm run webpack")
    
    console.log("Copy html...")
    process.execSync("mkdir dist/ui/")
    process.execSync("cp *.png dist/ui/")
    process.execSync("cp ui/*.jpg dist/ui/")
    process.execSync("cp ui/*.html dist/ui/")
    
    console.log("Copy lib...")
    process.execSync("mkdir dist/lib/")
    process.execSync("cp -r lib/* dist/lib/")
} else {
    process.execSync("rd /s /q dist")
    
    console.log("Build js...")
    process.execSync("mkdir dist")
    process.execSync("npm run webpack")
    
    // 这里将你不用编译的拷贝到dist目录 比如html图片等
    // 因为项目不同 文件不同 所以这里我就不统一实现了

    console.log("Copy html...")
    process.execSync("mkdir dist/ui/")
    process.execSync("copy ui/*.jpg dist/ui/")
    process.execSync("copy ui/*.html dist/ui/")
    
    console.log("Copy lib...")
    process.execSync("mkdir dist/lib/")
    process.execSync("copy -r lib/* dist/lib/")
}

console.log("Build index.html...")
let indexHtml_src = fs.readFileSync("index.html", "utf-8")
indexHtml_src = indexHtml_src.replace("type=\"module\"", "")
fs.writeFileSync("dist/index.html", indexHtml_src)

if (!win) {
    console.log("Install to Android project..")
    process.execSync("rm -rf ../../../hos-native-Android/app/src/main/assets/WWW")
    process.execSync("cp -r ./dist ../../../hos-native-Android/app/src/main/assets/WWW")
}